package com.ruoyi.lyy.controller;


import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.lyy.domain.dto.UpdateOrderDTO;
import com.ruoyi.lyy.domain.vo.OrderVO;
import com.ruoyi.lyy.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author YueYang
 * Created on 2025/11/18 21:53
 * @version 1.0
 */
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final IOrderService orderService;

    /**
     * 更新订单状态
     *
     * @param id             订单id
     * @param updateOrderDTO 更新订单状态DTO
     * @return 影响行数
     */
    @PutMapping("/{orderId}")
    public AjaxResult updateOrderById(@PathVariable("orderId") Integer id, @RequestBody UpdateOrderDTO updateOrderDTO) {
        int row = orderService.updateOrderById(id, updateOrderDTO);
        if (row > 0) {
            return AjaxResult.success("更新订单状态成功");
        } else {
            return AjaxResult.error("更新订单状态失败");
        }
    }

    /**
     * 根据订单id查询订单信息
     *
     * @param id 订单id
     * @return 订单信息
     */
    @GetMapping("/{orderId}")
    public AjaxResult getOrderById(@PathVariable("orderId") Integer id) {
        OrderVO orderVO = orderService.getOrderById(id);
        if (orderVO != null) {
            return AjaxResult.success("查询订单成功", orderVO);
        } else {
            return AjaxResult.error("查询订单失败");
        }
    }


}
